package logic

import (
	"context"
	"errors"
	"go.uber.org/zap"
	"smart-health-platforms/pkg"
	"user_srv/internal/dao"
	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateFaseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateFaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateFaseLogic {
	return &UpdateFaseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 修改人脸
func (l *UpdateFaseLogic) UpdateFase(in *user.UpdateFaseRequest) (*user.UpdateFaseResponse, error) {
	if in.UserId <= 0 {
		pkg.Error("用户ID不能为空")
		return nil, errors.New("用户ID不能为空")
	}
	if in.Image == "" {
		pkg.Error("图片路径不能为空")
		return nil, errors.New("图片路径不能为空")
	}

	err := dao.UpdateFase(int(in.UserId), in.Image)
	if err != nil {
		pkg.Error("修改失败", zap.Error(err))
		return nil, err
	}

	return &user.UpdateFaseResponse{
		Msg: "修改成功",
	}, nil
}
